package cn.sinata.wanglin.utils;

import com.xilada.xldutils.utils.TimeUtils;
import com.xilada.xldutils.utils.Utils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Calendar;
import java.util.concurrent.ExecutionException;

/**
 * description：
 * Created by kaihongwu on 2016/12/26 下午 9:48
 */
public class StringToUtils {
    public static String toOld(String time) {
        String ageBetween=null;
        try {
        String bornYear=  TimeUtils.getTimeYear(time);
        Calendar now = Calendar.getInstance();
        int currentYear=  now.get(Calendar.YEAR);
        int age= currentYear- Integer.parseInt(bornYear);
        int lower = (age - age % 5);
        int upper = lower + 5;
        ageBetween=lower+"-"+upper+"岁";
        }catch (Exception e){
            ageBetween="暂无";
            e.printStackTrace();
        }
        return ageBetween;
    }

    public static String URLEncode(String content){
        if (content == null) {
            return content;
        }
        try {
            content = URLEncoder.encode(content,"utf-8");
        }catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return content;
    }

    public static String URLDecode(String content){
        if (content == null) {
            return content;
        }
        try {
            content = URLDecoder.decode(content,"utf-8");
        }catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return content;
    }
}
